package com.ehi.common.jersey.filter;

import com.ehi.common.test.jersey.AbstractServletContainerWithMemcachedIntTest;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.server.ServerProperties;
import org.glassfish.jersey.test.DeploymentContext;
import org.glassfish.jersey.test.ServletDeploymentContext;
import org.junit.Test;

import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import static org.assertj.core.api.Assertions.assertThat;

public class NoCacheControlFilterIntTest extends AbstractServletContainerWithMemcachedIntTest {

    @Override
    protected void configureClient(ClientConfig config) {
        config.register(JacksonFeature.class);
        super.configureClient(config);
    }

    @Override
    protected DeploymentContext configureServletContext() {
        return ServletDeploymentContext.forServlet(org.glassfish.jersey.servlet.ServletContainer.class)
            .contextParam("contextConfigLocation", "classpath:applicationContext.xml")
            .addListener(org.springframework.web.context.ContextLoaderListener.class).servletPath("/api")
            .initParam(ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, "true")
            .initParam("javax.ws.rs.Application", "com.ehi.common.jersey.status.TestApplication").contextPath("/rb")
            .build();
    }

    @Test
    public void shouldHaveCacheControlHeaderWithNoCache() {
        Response response = target("test/valid").request().accept(MediaType.APPLICATION_JSON).get();
        assertThat(response.getHeaderString(HttpHeaders.CACHE_CONTROL)).isEqualTo("no-cache");
    }

}
